<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>TagM: RTOS::task Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">TagM
   &#160;<span id="projectnumber">1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="class_r_t_o_s.html">RTOS</a></li><li class="navelem"><a class="el" href="class_r_t_o_s_1_1task.html">task</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#friends">Friends</a>  </div>
  <div class="headertitle">
<div class="title">RTOS::task Class Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>an independent thread of execution  
 <a href="class_r_t_o_s_1_1task.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="p_r_t_o_s_8h_source.html">pRTOS.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for RTOS::task:</div>
<div class="dyncontent">
 <div class="center">
  <img src="class_r_t_o_s_1_1task.png" usemap="#RTOS::task_map" alt=""/>
  <map id="RTOS::task_map" name="RTOS::task_map">
<area href="class_beeper.html" title="Generates instructed sounds by switching the beeper on and off." alt="Beeper" shape="rect" coords="139,56,268,80"/>
<area href="class_game_handler.html" title="Responsible for handling the entire game. Reacts from incoming signals from OperationController, Health and GameTime." alt="GameHandler" shape="rect" coords="139,112,268,136"/>
<area href="class_game_time.html" title="Tracking and sharing gametime (in seconds), gives signal when the playtime is identical to the gameti..." alt="GameTime" shape="rect" coords="139,168,268,192"/>
<area href="class_health.html" title="Responsible for the players health, gives signal when health becomes zero or less." alt="Health" shape="rect" coords="139,224,268,248"/>
<area href="class_i_r_sensor.html" title="Listens to the IR signal. When a usefull command is received the IRSensor looks what he can do with i..." alt="IRSensor" shape="rect" coords="139,280,268,304"/>
<area href="class_i_r_simulatie.html" title="ONLY FOR TESTING!! Send signals that would normally come from the IRSensor." alt="IRSimulatie" shape="rect" coords="139,336,268,360"/>
<area href="class_log.html" title="Logs the Gametime, Health and WeaponID when the player gets hit. Resets and gets entire log when requ..." alt="Log" shape="rect" coords="139,392,268,416"/>
<area href="class_operation_controller.html" title="Starts and stops the entire game. At start gives Log command to clear the log." alt="OperationController" shape="rect" coords="139,448,268,472"/>
<area href="class_process_hit_controller.html" title="When an player gets hit the ProcessHitController gets all information and sends it to the log..." alt="ProcessHitController" shape="rect" coords="139,504,268,528"/>
<area href="class_read_log_handler.html" title="Communicates with the log and receives signals from the IRSensor. Sends the data from the Log to the ..." alt="ReadLogHandler" shape="rect" coords="139,560,268,584"/>
<area href="class_sound_controller.html" title="Receives sound commands and translates these commands to proper Hertz and Seconds for the Beeper..." alt="SoundController" shape="rect" coords="139,616,268,640"/>
</map>
 </div></div>

<p><a href="class_r_t_o_s_1_1task-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:ae50f0e253e66c53e3b28e388133c8fe7"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ae50f0e253e66c53e3b28e388133c8fe7">task</a> (unsigned int <a class="el" href="class_r_t_o_s_1_1task.html#ac5a30dff650f3b714491509cabad5dff">priority</a>=RTOS_MAX_PRIORITY, const char *tname=&quot;&quot;, unsigned int stacksize=RTOS_DEFAULT_STACK_SIZE)</td></tr>
<tr class="memdesc:ae50f0e253e66c53e3b28e388133c8fe7"><td class="mdescLeft">&#160;</td><td class="mdescRight">constructor, specify priority, name and stacksize  <a href="#ae50f0e253e66c53e3b28e388133c8fe7"></a><br/></td></tr>
<tr class="memitem:a5035326ddaf51d9219a17ca6c5a23c83"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a5035326ddaf51d9219a17ca6c5a23c83"></a>
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a5035326ddaf51d9219a17ca6c5a23c83">~task</a> (void)</td></tr>
<tr class="memdesc:a5035326ddaf51d9219a17ca6c5a23c83"><td class="mdescLeft">&#160;</td><td class="mdescRight">throws an error, beacuse tasks should never be destroyed <br/></td></tr>
<tr class="memitem:a2e0e3c92d9479336535a2ef877103f36"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a2e0e3c92d9479336535a2ef877103f36">suspend</a> (void)</td></tr>
<tr class="memdesc:a2e0e3c92d9479336535a2ef877103f36"><td class="mdescLeft">&#160;</td><td class="mdescRight">suspend a task (prevent execution until a resume)  <a href="#a2e0e3c92d9479336535a2ef877103f36"></a><br/></td></tr>
<tr class="memitem:a841b14aaab18d883959f034510dd9376"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a841b14aaab18d883959f034510dd9376">resume</a> (void)</td></tr>
<tr class="memdesc:a841b14aaab18d883959f034510dd9376"><td class="mdescLeft">&#160;</td><td class="mdescRight">continue a suspended task  <a href="#a841b14aaab18d883959f034510dd9376"></a><br/></td></tr>
<tr class="memitem:aa3eec7220a2724d30e2156cc395035f2"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#aa3eec7220a2724d30e2156cc395035f2">release</a> (void)</td></tr>
<tr class="memdesc:aa3eec7220a2724d30e2156cc395035f2"><td class="mdescLeft">&#160;</td><td class="mdescRight">release the CPU to the scheduler  <a href="#aa3eec7220a2724d30e2156cc395035f2"></a><br/></td></tr>
<tr class="memitem:a9d639b6f1147e0e3dbc603cdd8c52bd4"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a9d639b6f1147e0e3dbc603cdd8c52bd4">sleep</a> (unsigned int time)</td></tr>
<tr class="memdesc:a9d639b6f1147e0e3dbc603cdd8c52bd4"><td class="mdescLeft">&#160;</td><td class="mdescRight">wait for some time  <a href="#a9d639b6f1147e0e3dbc603cdd8c52bd4"></a><br/></td></tr>
<tr class="memitem:ac5a30dff650f3b714491509cabad5dff"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ac5a30dff650f3b714491509cabad5dff"></a>
unsigned int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ac5a30dff650f3b714491509cabad5dff">priority</a> (void) const </td></tr>
<tr class="memdesc:ac5a30dff650f3b714491509cabad5dff"><td class="mdescLeft">&#160;</td><td class="mdescRight">report the task priority <br/></td></tr>
<tr class="memitem:a56e4d07750c49b6620b0407013b177c1"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a56e4d07750c49b6620b0407013b177c1"></a>
const char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a56e4d07750c49b6620b0407013b177c1">name</a> (void) const </td></tr>
<tr class="memdesc:a56e4d07750c49b6620b0407013b177c1"><td class="mdescLeft">&#160;</td><td class="mdescRight">report the task name <br/></td></tr>
<tr class="memitem:ab02fe6432956956957bb2629dc9a3031"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ab02fe6432956956957bb2629dc9a3031"></a>
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ab02fe6432956956957bb2629dc9a3031">is_suspended</a> (void) const </td></tr>
<tr class="memdesc:ab02fe6432956956957bb2629dc9a3031"><td class="mdescLeft">&#160;</td><td class="mdescRight">report whether the task is currently suspended <br/></td></tr>
<tr class="memitem:a1e0b2566b673b0e4e6efd63a80284d35"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a1e0b2566b673b0e4e6efd63a80284d35"></a>
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a1e0b2566b673b0e4e6efd63a80284d35">is_blocked</a> (void) const </td></tr>
<tr class="memdesc:a1e0b2566b673b0e4e6efd63a80284d35"><td class="mdescLeft">&#160;</td><td class="mdescRight">report whether the task is currently blocked <br/></td></tr>
<tr class="memitem:a8ec666474a7668f78da3438dfa818a8e"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8ec666474a7668f78da3438dfa818a8e"></a>
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a8ec666474a7668f78da3438dfa818a8e">is_ready</a> (void) const </td></tr>
<tr class="memdesc:a8ec666474a7668f78da3438dfa818a8e"><td class="mdescLeft">&#160;</td><td class="mdescRight">report whether the task is currently ready for execution <br/></td></tr>
<tr class="memitem:a76913289a89a86fcf40171e28bfcfe98"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a76913289a89a86fcf40171e28bfcfe98"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a76913289a89a86fcf40171e28bfcfe98">logging_set</a> (bool log)</td></tr>
<tr class="memdesc:a76913289a89a86fcf40171e28bfcfe98"><td class="mdescLeft">&#160;</td><td class="mdescRight">for debugging: switch logging on or off <br/></td></tr>
<tr class="memitem:ac94209dd2efea030a70d48dabc890f38"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ac94209dd2efea030a70d48dabc890f38"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#ac94209dd2efea030a70d48dabc890f38">print</a> (std::ostream &amp;stream, bool header=true) const </td></tr>
<tr class="memdesc:ac94209dd2efea030a70d48dabc890f38"><td class="mdescLeft">&#160;</td><td class="mdescRight">print task statistics <br/></td></tr>
<tr class="memitem:a6fc603d0f1c8a94813586d3dfd123fcc"><td class="memItemLeft" align="right" valign="top"><a class="el" href="class_r_t_o_s_1_1event.html">event</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a6fc603d0f1c8a94813586d3dfd123fcc">wait</a> (void)</td></tr>
<tr class="memdesc:a6fc603d0f1c8a94813586d3dfd123fcc"><td class="mdescLeft">&#160;</td><td class="mdescRight">wait for all waitables created for this task  <a href="#a6fc603d0f1c8a94813586d3dfd123fcc"></a><br/></td></tr>
<tr class="memitem:a7b20fada91e6d232f6791ebc9675e3fc"><td class="memItemLeft" align="right" valign="top"><a class="el" href="class_r_t_o_s_1_1event.html">event</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a7b20fada91e6d232f6791ebc9675e3fc">wait</a> (const <a class="el" href="class_r_t_o_s_1_1waitable.html">waitable</a> &amp;w)</td></tr>
<tr class="memdesc:a7b20fada91e6d232f6791ebc9675e3fc"><td class="mdescLeft">&#160;</td><td class="mdescRight">wait for a single waitable  <a href="#a7b20fada91e6d232f6791ebc9675e3fc"></a><br/></td></tr>
<tr class="memitem:a09111916c62632df3042f5991ac7ab42"><td class="memItemLeft" align="right" valign="top"><a class="el" href="class_r_t_o_s_1_1event.html">event</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a09111916c62632df3042f5991ac7ab42">wait</a> (const <a class="el" href="class_r_t_o_s_1_1event.html">event</a> &amp;<a class="el" href="class_r_t_o_s_1_1task.html#aebeb5ca826f7137a66474bbee3bf74a1">set</a>)</td></tr>
<tr class="memdesc:a09111916c62632df3042f5991ac7ab42"><td class="mdescLeft">&#160;</td><td class="mdescRight">wait for a set of waitables  <a href="#a09111916c62632df3042f5991ac7ab42"></a><br/></td></tr>
<tr class="memitem:aebeb5ca826f7137a66474bbee3bf74a1"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aebeb5ca826f7137a66474bbee3bf74a1"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#aebeb5ca826f7137a66474bbee3bf74a1">set</a> (<a class="el" href="class_r_t_o_s_1_1flag.html">flag</a> &amp;w)</td></tr>
<tr class="memdesc:aebeb5ca826f7137a66474bbee3bf74a1"><td class="mdescLeft">&#160;</td><td class="mdescRight">set a flag <br/></td></tr>
<tr class="memitem:a0ea383a40c40d9f69fe8e29fb36fa40d"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#a0ea383a40c40d9f69fe8e29fb36fa40d">ignore_activation_time</a> (void)</td></tr>
<tr class="memdesc:a0ea383a40c40d9f69fe8e29fb36fa40d"><td class="mdescLeft">&#160;</td><td class="mdescRight">ignore this activation for the statistics  <a href="#a0ea383a40c40d9f69fe8e29fb36fa40d"></a><br/></td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr class="memitem:addc6d52f8792ddba1158d7ae5ef0037d"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d">main</a> (void)=0</td></tr>
<tr class="memdesc:addc6d52f8792ddba1158d7ae5ef0037d"><td class="mdescLeft">&#160;</td><td class="mdescRight">task body, must be provided by a derived class  <a href="#addc6d52f8792ddba1158d7ae5ef0037d"></a><br/></td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2><a name="friends"></a>
Friends</h2></td></tr>
<tr class="memitem:a01d2f5a71b8cd797b5f01fb6940ea353"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a01d2f5a71b8cd797b5f01fb6940ea353"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>periodic_task</b></td></tr>
<tr class="memitem:a0ee29d8961a0b67cea2c3fa76da116da"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a0ee29d8961a0b67cea2c3fa76da116da"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>waitable_set</b></td></tr>
<tr class="memitem:a2d8be07618a92a592c4905e969f9927f"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a2d8be07618a92a592c4905e969f9927f"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>flag</b></td></tr>
<tr class="memitem:aa5b30b5b619f01a5d94b779bf0e58610"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa5b30b5b619f01a5d94b779bf0e58610"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>RTOS</b></td></tr>
<tr class="memitem:a972487b0f63ae9fefb7f6642dae2d452"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a972487b0f63ae9fefb7f6642dae2d452"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><b>task_trampoline</b> (void)</td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>an independent thread of execution </p>
<pre class="fragment">  A task is an independent thread of execution, using its own stack. 
  Tasks share the single CPU, so only one task can be running at any time. 
  The RTOS determines which task is running. 
  A task has two bi-value states that determine whether 
  the task is runnable: the suspended/resumed flag and the 
  waiting/non-waiting flag. 
  A task is runnable only when it is both resumed, and non-waiting. 
  When a task is created it is resumed and non-waiting. 
  ll tasks (and the RTOS code) run in the same memory space, 
  without protection from each other. 
  So a 'wild pointer' in one task can destroy data in 
  another task, or even in the RTOS. 

  Each task is created with a fixed priority, which can be any 
  unsigend integer value below RTOS_MAX_PRIORITY (by default 10_000). 
  After creation the priority can not be changed.
  The value 0 indicates the highest task priority, a higher number 
  indicates a lower priority. 
  Each task must have a unqiue priority, it is an error to create 
  a task with same priority as an existing task. 
  You can omit the priority, in which case the RTOS will 
  select an unused priority starting at RTOS_MAX_PRIORITY 
  (in other words, it will choose a low priority for your task).

  Each task has its own stack. 
  You can specify the size of the stack at task creation. 
  If you omit the stack size, RTOS_DEFAULT_STACK_SIZE will be used 
  (default: 2 Kb). 
  This will be enough for most tasks, if you take care not to 
  allocate big things on the stack, and avoid very deep nesting 
  (watch out for recursion!).

  A task is created by instatiating a class that derives from 
  RTOS::task and supplies a main(). 
  This main() should never return. 
  The fragment below shows how you can do this. 
  The task name is used for statistics and debugging. 
  As shown for the name, it might be wise to get the task parameters 
  as arguments to the constructor of your task.

  @code 
</pre><p> class my_task_class : public <a class="el" href="class_r_t_o_s_1_1task.html" title="an independent thread of execution">RTOS::task</a> { public: my_task_class( const char *name ): task( name, // name of the task 10, // task priority 4096 // task stack size ){} private: void <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main( void )</a>{ // put the code of your task here } }; my_task_class my_task( "my first task" ); my_task_class my_task( "my second task" );  </p>
<pre class="fragment">  The example below is a complete program that shows the 
  standard part (initialization, and a main that calls 
  RTOS::run()), a function for writing to an individual LED, 
  a task class that blinks a LED, and two instatiations of 
  this class. 
  Note that the sleep() is call used instead of mkt_wait_ms 
  or mkt_wait_us. Sleep() causes other tasks to run while 
  this taks is waiting, whereas the mkt_wait_* calls would 
  use monopolize the CPU to do a busy wait.

  Subseqent examples will not show the standard 
  initialization (the part up to the comment line).

  @code 
</pre><p> #configure board hu_arm_v4 #configure clcd_lines 2 #configure memory rom #configure baudrate 38400</p>
<p>#include "pRTOS.h"</p>
<p>int <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main( void )</a>{ <a class="el" href="class_r_t_o_s.html#a27731fa3169d3337e826ff0c9994c384" title="runs the scheduler">RTOS::run()</a>; return 0; }</p>
<p>// end of standard part</p>
<p>void led_set( int n, int v ){ static int leds = 0; if( v ){ leds |= 1 &lt;&lt; n; } else { leds &amp;=~ 1 &lt;&lt; n; } mkt_leds_write( leds ); }</p>
<p>class blinker : public <a class="el" href="class_r_t_o_s_1_1task.html" title="an independent thread of execution">RTOS::task</a> { public: blinker( int LED, int period ): LED( LED ), period( period ){} private: int LED, period; void <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main( void )</a>{ for(;;){ led_set( LED, 1 ); sleep( period / 2 ); led_set( LED, 0 ); sleep( period / 2 ); } } };</p>
<p>blinker led0( 0, 1000 MS ); blinker led1( 1,  300 MS );  </p>
<pre class="fragment">  A task can be suspended and resumed by the task::suspend()
  and task::resume() calls. 
  The suspend/resume state does not count the number of suspends 
  and resumes: a suspend call on an already suspended task 
  (or a resume on an already resumed task) has no effect. 
  Suspend and resume are intended for use by the application code: 
  the RTOS will never suspend or resume a task. 
  (The RTOS uses the waiting/non-waiting state, which can 
  not be changed directly by the application.)

  The example below shows one task that beeps the speaker at 1 kHz, 
  while the other taks suspends and resumes the first task to make 
  it beep 5 times, after which it suspends itself, which ends all 
  activity. 
  (This will trigger the RTOS deadlock detection, because a normal 
  embedded application should never terminate.)

  @code 
</pre><p> class beeper : public <a class="el" href="class_r_t_o_s_1_1task.html" title="an independent thread of execution">RTOS::task</a> { public: unsigned int speaker; beeper( unsigned int speaker ): speaker( speaker ){} void <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main( void )</a>{ mkt_pin_configure( speaker, mkt_output); for(;;){ mkt_pin_write( speaker, 1  ); sleep( 500 US ); mkt_pin_write( speaker, 0  ); sleep( 500 US ); } } }; beeper speaker( 10 );</p>
<p>class suspender : public <a class="el" href="class_r_t_o_s_1_1task.html" title="an independent thread of execution">RTOS::task</a> { void <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main( void )</a>{ for( int i = 0; i &lt; 5 ; i++ ){ speaker.resume(); sleep( 500 MS ); speaker.suspend(); sleep( 1 S ); } <a class="el" href="class_r_t_o_s_1_1task.html#a2e0e3c92d9479336535a2ef877103f36" title="suspend a task (prevent execution until a resume)">suspend()</a>; } }; suspender task2;  </p>
</div><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="ae50f0e253e66c53e3b28e388133c8fe7"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">RTOS::task::task </td>
          <td>(</td>
          <td class="paramtype">unsigned int&#160;</td>
          <td class="paramname"><em>priority</em> = <code>RTOS_MAX_PRIORITY</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>tname</em> = <code>&quot;&quot;</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned int&#160;</td>
          <td class="paramname"><em>stacksize</em> = <code>RTOS_DEFAULT_STACK_SIZE</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>constructor, specify priority, name and stacksize </p>
<p>Priorities are reasonably-valued (below RTOS_DEFAULT_RIORITY) unsigned integers. 0 is te highest priority. Priorities must be unqiue. The default causes the constructor to choose a free priority starting at RTOS_DEFAULT_PRIORITY (default: 10000).</p>
<p>The name is used for debugging and statistics.</p>
<p>A stack of stack_size bytes is allocated for the task. The default is 2 kB. </p>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a0ea383a40c40d9f69fe8e29fb36fa40d"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::task::ignore_activation_time </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>ignore this activation for the statistics </p>
<p>Calling this function makes the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> statistics ignore the current task activation as far as statistics is concerned. You can use this to avoid pullution of your task statistics with the timing effects of debug logging. But make sure you don't use it in the 'normal' execution paths, becaue that would make the statitics lie to you. </p>

</div>
</div>
<a class="anchor" id="addc6d52f8792ddba1158d7ae5ef0037d"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void RTOS::task::main </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>task body, must be provided by a derived class </p>
<p>A task is created by inheriting from task and providing a <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main()</a> function. Initialisation of the task, including creating its waitables, should be done in the constructor. Don't forget to call the constructor of the task class!</p>
<p>The <a class="el" href="class_r_t_o_s_1_1task.html#addc6d52f8792ddba1158d7ae5ef0037d" title="task body, must be provided by a derived class">main()</a> is the body of the task. It should never terminate.</p>
<p>Each task has a unique priority (an unsigned integer). A lower value indicates a higher priority. The <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> scheduler will always run the task with the higest-priority runnable (neither blocked nor suspended) task. A task runs until it changes this 'situation' by using an <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> call that changes its own state to not runnable, or the state of a higher priority task to runnable.</p>
<p>Timers are served only when the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> is activated by calling any of its state-changing interfaces. Hence the longest run time between such calls determines the granularity (timewise responsiveness) of the application. Within a timeconsuming computation a task can call <a class="el" href="class_r_t_o_s_1_1task.html#aa3eec7220a2724d30e2156cc395035f2" title="release the CPU to the scheduler">release()</a> to have the <a class="el" href="class_r_t_o_s.html" title="static class, namespace-like container for RTOS declarations">RTOS</a> serve the timers. </p>

<p>Implemented in <a class="el" href="class_i_r_simulatie.html#ae2f018d9aa6faf6559518404b23ba295">IRSimulatie</a>.</p>

</div>
</div>
<a class="anchor" id="aa3eec7220a2724d30e2156cc395035f2"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::task::release </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>release the CPU to the scheduler </p>
<p>Sevices timers and releases the CPU to a higher priority task if one became ready. </p>

</div>
</div>
<a class="anchor" id="a841b14aaab18d883959f034510dd9376"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::task::resume </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>continue a suspended task </p>
<p>Has no effect when the task is not suspended.</p>
<p>Can be extended by an application task to suit its needs. </p>

</div>
</div>
<a class="anchor" id="a9d639b6f1147e0e3dbc603cdd8c52bd4"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::task::sleep </td>
          <td>(</td>
          <td class="paramtype">unsigned int&#160;</td>
          <td class="paramname"><em>time</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>wait for some time </p>
<p>Sleeps the task (prevents execution) for the indicated time. </p>

</div>
</div>
<a class="anchor" id="a2e0e3c92d9479336535a2ef877103f36"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::task::suspend </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>suspend a task (prevent execution until a resume) </p>
<p>Suspends the task (prevents execution). Has no effect when the task is already suspended. Can be extended by an application task.</p>
<p>A concrete task can extend this operation to suit its needs. </p>

</div>
</div>
<a class="anchor" id="a6fc603d0f1c8a94813586d3dfd123fcc"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_r_t_o_s_1_1event.html">event</a> RTOS::task::wait </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>wait for all waitables created for this task </p>
<p>Wait (prevent execution) until at least one of the waitables is set. Return and clear that waitable. Three variants for the parameter:</p>
<ul>
<li>The default (no parameter) waits for all waitables defined for the task.</li>
<li>One waitable as argument waits for that specific waitable.</li>
<li>The addition (operator+) of waitables: wait for any one of those waitables.</li>
</ul>
<p>It is an error to wait for waitables that have not been created for this task. </p>

</div>
</div>
<a class="anchor" id="a7b20fada91e6d232f6791ebc9675e3fc"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_r_t_o_s_1_1event.html">event</a> RTOS::task::wait </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="class_r_t_o_s_1_1waitable.html">waitable</a> &amp;&#160;</td>
          <td class="paramname"><em>w</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>wait for a single waitable </p>
<p>Wait (prevent execution) until at least one of the waitables is set. Return and clear that waitable. Three variants for the parameter:<ul>
<li>The default (no parameter) waits for all waitables defined for the task.</li>
<li>One waitable as argument waits for that specific waitable.</li>
<li>The addition (operator+) of waitables: wait for any one of those waitables.</li>
</ul>
It is an error to wait for waitables that have not been created for this task.  </p>

</div>
</div>
<a class="anchor" id="a09111916c62632df3042f5991ac7ab42"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_r_t_o_s_1_1event.html">event</a> RTOS::task::wait </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="class_r_t_o_s_1_1event.html">event</a> &amp;&#160;</td>
          <td class="paramname"><em>set</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>wait for a set of waitables </p>
<p>Wait (prevent execution) until at least one of the waitables is set. Return and clear that waitable. Three variants for the parameter:<ul>
<li>The default (no parameter) waits for all waitables defined for the task.</li>
<li>One waitable as argument waits for that specific waitable.</li>
<li>The addition (operator+) of waitables: wait for any one of those waitables.</li>
</ul>
It is an error to wait for waitables that have not been created for this task.  </p>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="p_r_t_o_s_8h_source.html">pRTOS.h</a></li>
<li>pRTOS.cpp</li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Jun 27 2012 11:07:15 for TagM by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.1
</small></address>
</body>
</html>
